package com.hzjh.h5mall.ui.wallet

import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.hzjh.base.ext.R
import com.hzjh.base.ext.frame.JHBaseActivity
import com.hzjh.base.ext.route.RouteUrl
import com.hzjh.base.ext.widget.balloon.CommonTipBalloon
import com.hzjh.base.frame.adapter.MutableAdapter
import com.hzjh.h5mall.adapter.wallet.WalletProcessVH
import com.hzjh.h5mall.databinding.ActivityEarningDetailBinding
import com.hzjh.h5mall.databinding.ItemWalletProcessBinding
import com.hzjh.h5mall.model.wallet.WalletVM
import com.skydoves.balloon.balloon

//广告 分成  盲盒收益详情
@Route(path = RouteUrl.EARNING_DETAIL_ACTIVITY)
class EarningDetailActivity : JHBaseActivity<ActivityEarningDetailBinding,WalletVM>() {
    @JvmField
    @Autowired(name = RouteUrl.PARAMS_WALLET_ID)
    var id = ""
    private val balloon by balloon<CommonTipBalloon>()
    private val processAdapter by lazy {
        MutableAdapter(viewModel.processList.value!!).apply {
            addVhDelegate {
                WalletProcessVH(
                    ItemWalletProcessBinding.inflate(layoutInflater, it, false),
                    clickFailed ={view,message->
                        //弹气泡提示
                        balloon.showAlignBottom(view)
                        balloon.getContentView().apply {
                            findViewById<TextView>(R.id.tv_message).text = message
                        }
                    }){position ->
                    //是否最后一个item
                    position != viewModel.processList.value!!.size-1
                }
            }
        }
    }
    override fun initData() {
        viewModel.reqWalletDetail(id)
    }

    override fun initView() {
        viewBinding.rvProcess.layoutManager = LinearLayoutManager(this)
        viewBinding.rvProcess.adapter=processAdapter
    }

    override fun initObservable() {
        super.initObservable()
        viewModel.walletDetailBean.observe(this){
            viewBinding.tvOrderMoney.text=it.number
            viewBinding.tvCreateTime.text=it.createTime
            viewBinding.tvTypeValue.text=it.type
            viewBinding.tvOrderId.text=it.id
            viewModel.getProcessList(it)
        }
        viewModel.processList.observe(this){
            processAdapter.notifyDataSetChanged()
        }
    }

    override fun initViewBinding(): ActivityEarningDetailBinding {
        return ActivityEarningDetailBinding.inflate(layoutInflater)
    }
}